package com.meizi.threalocad.controller;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.TtlRunnable;

import java.util.concurrent.TimeUnit;

/**
 * @author Administration
 * @date 2021/5/19 - 10:30 - 星期三
 * @project lambda-stuty
 * @package com.meizi.threalocd.controller
 * @by GGbomd猪猪侠
 */
// 父-子线程
public class TtlSample1Controller {



    static TransmittableThreadLocal<String> ttl = new TransmittableThreadLocal<>();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            // 在父线程中设置值
            ttl.set("throwable");
            new Thread(TtlRunnable.get(() -> {
                methodFrame1();
            }),"childThread").start();
        },"parentThread").start();
        TimeUnit.SECONDS.sleep(Long.MAX_VALUE);
    }


    private static void methodFrame1() {
        methodFrame2();
    }

    private static void methodFrame2() {
        System.out.println(ttl.get());
    }
}
